/*
 * trace_VariableInfo.c
 *
 *  Created on: 2012/07/10
 *      Author: guanxiaoying
 */

#include "../table.h"
#include "../trace_cmd_table.h"
typedef struct _TRVARIABLEINFO
{
	U4 attr;
	U4 flag;
	AST astVari;
	AST astNext;
	AST astBefore;
	TRVALUESCP valScp;
	TRVALUESCP negValScp;
} TRVARIABLEINFO, *PTRVARIABLEINFO;

#define TableSize  (sizeof(TRVARIABLEINFO ))
#define TableType  PTRVARIABLEINFO
#define stTable stTrVariableManager.memoryBlocks
#define maxTable stTrVariableManager.maxRecordNum
#define  maxNumPerBlk  (stTrVariableManager.astMaxNum_Block)


static TABLEMANAGER stTrVariableManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stTrVariableManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stTrVariableManager, resetListener,  index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}
static BOOL ClearTable( VOID )
{
	return Clear_Com( &stTrVariableManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stTrVariableManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID ){
	return maxTable;
}
static U4 getAttr( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->attr;
}
static U4 setAttr( AST astIndex, U4 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->attr=value;
}
static U4 getFlag( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->flag;
}
static U4 setFlag( AST astIndex, U4 value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->flag=value;
}
static AST getVari( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astVari;
}
static AST setVari( AST astIndex, AST value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astVari=value;
}
static AST getPrev( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astBefore;
}
static AST setPrev( AST astIndex, AST value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astBefore=value;
}
static AST getNext( AST astIndex ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astNext;
}
static AST setNext( AST astIndex, AST value ){
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astNext=value;
}
static VOID getValueScope( AST astIndex, TRVALUESCP* vs){
	assert( vs != NULL );
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL ){
		return ;
	}
	*vs = pTbl->valScp;
}
static VOID setValueScope( AST astIndex, TRVALUESCP* vs){
	assert( vs != NULL );
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL ){
		return ;
	}
	pTbl->valScp = *vs;
}
static VOID getNegValueScope( AST astIndex, TRVALUESCP* vs){
	assert( vs != NULL );
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL ){
		return ;
	}
	*vs = pTbl->negValScp;
}
static VOID setNegValueScope( AST astIndex, TRVALUESCP* vs){
	assert( vs != NULL );
	TableType pTbl = core_getTable( astIndex );
	if( pTbl == NULL ){
		return ;
	}
	pTbl->negValScp = *vs;
}
const TRVARIABLEACCESS stTrVariableAccess={
		ClearTable,
		AllocTable,
		getMaxLineNum,
		{
				getVari,
				setVari
		},
		{
				getAttr,
				setAttr
		},
		{
				getFlag,
				setFlag
		},
		{
				getNext,
				setNext
		},
		{
				getPrev,
				setPrev
		},
		getValueScope,
		setValueScope,
		getNegValueScope,
		setNegValueScope
};





